<%@ page import="java.sql.*"%>

<html>
<head>
<title>Enquiry Form</title>
</head>
<%
	String url;
	url="Jdbc:Odbc:clientDSN";
	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
	Connection conn=DriverManager.getConnection(url,"scott","tiger");
	PreparedStatement pstmt=conn.prepareStatement("select * from property");;
	ResultSet results=pstmt.executeQuery();
	
 %>
<body>
<center>Enquiry Form</center>
 	<form name="ClientRequestForm" method="post" action="/TestForm/validate">
 		<table>
		<tr>
			<td>Name</td>
			<td><input type="text" name="nameText" size=20></input></td> 
		</tr>
		<tr>
			<td>Address	</td>
			<td><input type="text" name=addressText size=20></input></td>
		</tr>
		<tr>
			<td>Telephone number</td>
			<td><input type="text" name=telText size=10></input></td>
		</tr>
		</table>
		Preferred Location 
			
			<select name="stateSelect"><option  value="-1">select</option></td>
			<%
			 	while(results.next()){
				String name = results.getString(2);
				
				%><option value="<%= name %>"><%=name%></option>
				<%} results.close(); pstmt.close(); %>
				</select>
				
		  <br>
		  <input type=submit value="submit"></input>
		  <input type=submit value="Save" onClick="dataStore()"></input>
</form>
</body>
<script>

		function dataStore()
		{
			document.ClientRequestForm.action="/TestForm/DataStore";
		}	
		

		function isEmpty()
		{
			if(document.ClientRequestForm.nameText.value.length==0)
			{
				alert("name field cannot be empty");
				document.ClientRequestForm.nameText.focus();
				return false;
			}
			if (document.ClientRequestForm.addressText.value.length==0)	
			{
				alert("address field cannot be empty");
				document.ClientRequestForm.addressText.focus();
				return false;
			}
			

			if(document.ClientRequestForm.telText.value.length==0)
			{
				alert("Telephone field cannot be empty");
				document.ClientRequestForm.telText.focus();
				return false;
			}	

			if(document.ClientRequestForm.stateSelect.value=="-1")
			{
				alert("select a state");
				document.ClientRequestForm.stateSelect.focus();
				return false;
			}

			return true;
		}
				


</script>




</html>
